package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.PageModel;
import org.lanqiao.service.AdminServiceImpl;

/**
 * 模糊查询用户
 * Servlet implementation class MoUserServlet
 */
@WebServlet("/api/admin/MoUserServlet")
public class MoUserServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		/**
		 * page表示当前页数，pageSize表示每页显示页数
		 * name表示文本框输入内容
		 */
		String pageSize="10";
		String pageNum=request.getParameter("page");
		String name=request.getParameter("name");
		/**
		 * 调用模糊查询用户
		 */
		AdminServiceImpl abc=new AdminServiceImpl();
		JsonResult result=null;
		if(name!= null && name.length() != 0) {
			String names=name.replace(" ","");
			try {
				PageModel<List> model=abc.MoUsers(names,pageNum, pageSize);
				if(model!=null){
					result=new JsonResult("查询成功",Constants.STATUS_SUCCESS,model);
				}else {
					result=new JsonResult("查询错误",Constants.STATUS_UNFOUND);
				}
			} catch (Exception e) {
				result=new JsonResult("查询异常",Constants.STATUS_FAILURE);
			}
			JsonResultWriter.writer(response, result);
		 }
	}

}
